﻿Imports System
Imports System.Linq
Imports System.Data
Imports System.Web
Imports Equipment.DataAccess

Public Class UserWrapper

#Region "Properties"

    Public _siteID As Integer
    Public Property SiteID As Integer
        Get
            Return _siteID
        End Get
        Set(ByVal value As Integer)
            _siteID = value
        End Set
    End Property

    Public _id As Integer
    Public Property ID As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property

    Public _site As String
    Public Property Site As String
        Get
            Return _site
        End Get
        Set(ByVal value As String)
            _site = value
        End Set
    End Property

    Public _userName As String
    Public Property UserName As String
        Get
            Return _userName
        End Get
        Set(ByVal value As String)
            _userName = value
        End Set
    End Property

    Public _fullName As String
    Public Property FullName As String
        Get
            Return _fullName
        End Get
        Set(ByVal value As String)
            _fullName = value
        End Set
    End Property

    Public _email As String
    Public Property Email As String
        Get
            Return _email
        End Get
        Set(ByVal value As String)
            _email = value
        End Set
    End Property

    Public _securityRoles As String
    Public Property SecurityRoles As String
        Get
            Return _securityRoles
        End Get
        Set(ByVal value As String)
            _securityRoles = value
        End Set
    End Property

    Public _groups As String
    Public Property Groups As String
        Get
            Return _groups
        End Get
        Set(ByVal value As String)
            _groups = value
        End Set
    End Property

#End Region

    Public Shared Function ConvertToWrapperList(ByVal userSource As IEnumerable(Of Equipment.DataAccess.User)) As List(Of UserWrapper)
        Dim wrapperList As New List(Of UserWrapper)

        For Each u In userSource
            Dim w As New UserWrapper
            w.SiteID = u.SiteID
            w.ID = u.ID
            w.FullName = u.FullName
            w.Email = u.Email
            w.UserName = u.Username
            w.Site = u.Site.Description
            w.SecurityRoles = String.Join(", ", u.Roles.Select(Function(r) r.Description))
            w.Groups = String.Join(", ", u.Groups.Select(Function(g) g.Description))

            wrapperList.Add(w)
        Next

        Return wrapperList
    End Function
End Class
